<template>
    <view class="box_1">
        <view class="business-record">
            <view class="r-data">
                <view class="top_1_box">
                    <view  @tap="hanldeShowData1()"><image class="date_image" src="../../static/img/cash_date.png"></image></view>
                    <view class="d-time" @tap="hanldeShowData1()">日期选择</view>
                    <view  @tap="hanldeShowData1()"><image  class="date_image_2" src="../../static/img/sale_arrow_2.png"/></view>
                </view>
                <view class="search_box">
                    <view class="search_box_1"><image  class="search_box_img" src="../../static/img/search.png"/></view>
                    <view class="search_box_2"><input @confirm="wordInput($event)" placeholder="请输入姓名电话"/></view>
                </view>
            </view>
            <view class="team_bk_box">
                <view class="team_bk">
                    <view class="friendsNum">好友数：{{friendsNum}}</view>
                </view>
            </view>

            <view class="r-list">
                <view v-if="friendsList.length===0">
                    <mNodata></mNodata>
                </view>
                <view v-else class="l-box" v-for="(item,index) in friendsList" :key="index">
                    <view class="logo_name_box">
                        <view>
                            <view >
                                <view><image  :src="item.avatar"/></view>
                            </view>
                        </view>
                        <view class="new_box">
                            <view class="b-num">
                                <view class="n-title">{{item.nickname}}
                                    <image class="group_img" :src="img_root+'v'+item.member_id+'.png'"/>
                                </view>
                                <view class="n-title">{{item.mobile}}</view>
                            </view>
                            <view class="b-time">
                                <view class="t-title">添加时间：{{item.created_at}}</view>
                                <view class="t-status" >{{item.attribute_name}}</view>
                            </view>
                            <view class="b-time-1">
                                <view class="t-title">团队当月总拼团数：{{item.group_total_number}}</view>
                                <view class="t-title">团队当前活跃人数：{{item.group_active_total_number}}</view>
                            </view>

                        </view>
                    </view>
                </view>
            </view>
        </view>
<!--        <van-calendar-->
<!--                type="single"-->
<!--                :min-date="minDate"-->
<!--                :max-date="maxDate"-->
<!--                :show="beginShowData"-->
<!--                :default-date="defaultDate"-->
<!--                :title="'选择开始日期'"-->
<!--                :close-on-click-overlay="true"-->
<!--                @close="handleCloseData1"-->
<!--                @confirm="handleSubmitData1"-->
<!--        />-->
<!--        <van-calendar-->
<!--                type="single"-->
<!--                :min-date="minDate"-->
<!--                :max-date="maxDate"-->
<!--                :show="endShowData"-->
<!--                :default-date="defaultDate"-->
<!--                :title="'选择结束日期'"-->
<!--                :close-on-click-overlay="true"-->
<!--                @close="handleCloseData2"-->
<!--                @confirm="handleSubmitData2"-->
<!--        />-->

        <van-popup :show="beginShowData" position="bottom" :overlay="true"  @close="onClose($event)"
                   @touchmove.stop.prevent="moveHandle"
        >
            <van-datetime-picker
                    type="date"
                    title="选择开始日期"
                    :value="currentDate"
                    @cancel="handleCloseData1"
                    @confirm="handleSubmitData1"
            />
        </van-popup>

        <van-popup :show="endShowData" position="bottom" :overlay="true"  @close="onClose($event)"
                   @touchmove.stop.prevent="moveHandle"
        >
            <van-datetime-picker
                    type="date"
                    title="选择结束日期"
                    :value="currentDate"
                    @cancel="handleCloseData2"
                    @confirm="handleSubmitData2"
            />
        </van-popup>

    </view>
</template>

<script>
    export default {
        name: "myFriends",
        data() {
            return {
                friendsList:[],
                friendsNum:'',
                beginShowData:false,
                endShowData:false,
                minDate: new Date(2020, 0, 1).getTime(),
                maxDate: new Date().getTime(),
                defaultDate:new Date().getTime(),
                start_time:'',
                end_time:'',
                word:'',
                type:1,
                page:1,
                is_load:0,
                imgUrl:this.$mConfig.assetsPath,
                currentDate: new Date().getTime(),
                img_root:'../../static/img/',
            }
        },
        onShow() {
            this.word=''
            this.end_time=''
            this.start_time=''
            this.friendsList=[]
            this.getFriendsList()
        },
        onReachBottom()  {  //分页加载请求数据
            if(this.is_load>0){
                this.page++
                this.getFriendsList()
            }else{
                uni.showToast({
                    title:"没有更多数据啦",
                    icon:"none",
                })
            }
        },
        methods: {
            moveHandle () {},
            timestampToTime (cjsj) {
                let date = new Date(cjsj) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
                let Y = date.getFullYear() + '-'
                let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
                let D = date.getDate() + ' '
                return Y+M+D
            },
            onClose(){
                this.beginShowData=false
                this.endShowData=false
            },
            //开始日期
            hanldeShowData1(res){
                this.beginShowData=true
            },
            //关闭开始日期弹窗
            handleCloseData1(res){
                this.beginShowData=false
            },
            // //结束日期
            // hanldeShowData2(res){
            //     this.endShowData=true
            // },
            //关闭结束日期
            handleCloseData2(res){
                this.endShowData=false
            },
            //选择开始日期完成后
            handleSubmitData1(res){
                // let year=res.detail.getFullYear()
                // let month=res.detail.getMonth()+1
                // let day=res.detail.getDate()
                // this.start_time=year+'-'+month+'-'+day
                this.start_time=this.timestampToTime(res.detail)
                this.beginShowData=false
                this.endShowData=true
            },
            //选择结束日期完成后
           async handleSubmitData2(res){
                // let year=res.detail.getFullYear()
                // let month=res.detail.getMonth()+1
                // let day=res.detail.getDate()
                // this.end_time=year+'-'+month+'-'+day
               this.end_time=this.timestampToTime(res.detail)
                this.endShowData=false
                this.page=1
                this.is_load=0
                this.friendsList=[]
                await  this.getFriendsList()
            },
            async getFriendsList(){ // 获取朋友列表
                uni.showLoading({})
                let resData= await  this.$apis.myFriends({
                    page:this.page,
                    word:this.word,
                    type:this.type,
                    start_time:this.start_time,
                    end_time:this.end_time
                })
                if(resData.code===0){
                    this.friendsList.push(...resData.data.lists)
                    this.is_load=resData.data.is_load
                    this.friendsNum=resData.data.total_count
                }
                uni.hideLoading()
            },
           async wordInput(event){
                this.word=event.detail.value
                this.page=1
                this.is_load=0
                this.friendsList=[]
                await  this.getFriendsList()
            }
        },
    }
</script>
<style>
    page {
        background-color:#FAFAFA
    }
</style>
<style lang="less" scoped>
    .business-record{
        background-color: #ffffff;
        position: relative;
        width: 100%;
        /*margin-left: 50rpx;*/
        .r-data{
            /*position: fixed;*/
            background-color: #ffffff;
            width: 100%;
            height: 110rpx;
            display: flex;
            box-sizing: border-box;
            padding: 0 30rpx;
            justify-content: space-between;
            align-items: center;
            /*border-bottom: solid 1px #EDEDED;*/
            .d-time{
                font-size: 22rpx;
                color: #999999;
                width: 50rpx;
                margin-left: 10rpx;

            }
            .date_arrow_image{
                position: relative;
                width: 40rpx;
                height: 40rpx;
                /*margin-left: -120rpx;*/
            }
        }
        .r-list{
            width: 100%;
            box-sizing: border-box;
            padding: 80rpx 20rpx 0 20rpx;
            .l-box{
                box-sizing: border-box;
                border-bottom: solid 1px #EDEDED;
                padding: 35rpx 0;
                .b-num{
                    display: flex;
                    justify-content: space-between;
                    // line-height: 80rpx;
                    .n-title{
                        font-size: 26rpx;
                        color: #333333;

                    }
                    .n-money{
                        font-size: 26rpx;
                        color: #333333;
                        text-align: right;

                    }
                }
                .b-time{
                    padding-top: 20rpx;
                    display: flex;
                    justify-content: space-between;
                    // line-height: 80rpx;
                    .t-title{
                        font-size: 24rpx;
                        color: gray;
                    }
                    .t-status{
                        font-size: 24rpx;
                        color:#999999;
                    }
                }
                .b-time-1{
                    padding-top: 20rpx;
                    display: flex;
                    justify-content: space-between;
                    // line-height: 80rpx;
                    .t-title{
                        font-size: 24rpx;
                        color: gray;
                    }
                    .t-status{
                        margin-left: 10rpx;
                        font-size: 24rpx;
                        color:#999999;
                    }
                }
            }
        }
    }
    .business_number{
        display: flex;
        flex-direction: row;
        width: 226rpx;
        /*border: solid 0.5px #999999;*/
        border-radius: 10px;
        font-size: 25rpx;
        margin-right: -9px;
    }
    .search_image{
        margin-top: 7rpx;
        height: 35rpx;
        width: 35rpx;
    }
    .date_image{
        /*margin-left: 12rpx;*/
        height: 40rpx;
        width: 40rpx;
    }
    .date_image_2{
        /*margin-left: 12rpx;*/
        height: 17rpx;
        width: 30rpx;
        transform:  translate(0,20%);
        /*margin-left: 10rpx;*/
    }
    .empty_img{
        margin-top: 200rpx;
        width: 520rpx;
        height: 360rpx;
    }
    .empty_text{
        color: #333333;
        font-size: 26rpx;
        margin-top: 20rpx;
    }
    .empty_box{
        text-align: center;
    }
    .button_1{
        width: 108rpx;
        border: none;
        background-color: #FF9502;
        font-size:26rpx;
        color: #ffffff;
    }
    .button_1:nth-child(1){
        margin-right: 10rpx;
    }
    .total_cash{
        font-size: 26rpx;
        color: #F19317;
    }
    .top_1_box{
        display: flex;
        flex-direction: row;
    }
    .watch_all{
        margin-left: 20rpx;
        font-size: 25rpx;
        color: #333333;
        margin-top: 9rpx;
    }
    .n-money-text{
        margin-top: 20rpx;
        color:#999999;
    }
    .select_box{
        position: fixed;
        bottom: 0;
    }
    .search_box{
        display: flex;
        flex-direction: row;
        background-color: #E5E5E5;
        width: 450rpx;
        height: 80rpx;
        border-radius: 5px;
    }
    .search_box_img{
        width: 40rpx;
        height: 40rpx;
        transform: translate(0,10%);
        margin-left: 5rpx;
        margin-right: 10rpx;
    }
    .search_box_1{
        margin-top: 20rpx;
    }
    .search_box_2{
        margin-top: 20rpx;
    }
    .logo_name_box{
        display: flex;
        flex-direction: row;
        image{
            width: 100rpx;
            height: 100rpx;
            transform: translate(0,-8%);
            border-radius: 25px;
        }
    }
    .team_bk{
        background-image: url("https://qiniu.scxhrd.com/static/img/team_bk.png");
        background-size: 100%;
        background-repeat: no-repeat;
        width: 90%;
        height: 240rpx;
        margin-left: 5%;
    }
    .team_bk_box{

    }
    .friendsNum{
        border-radius: 5px;
        position: relative;
        background-color: #ffffff;
        color: #F57D25;
        font-size: 22rpx;
        width: 170rpx;
        height: 40rpx;
        top: 170rpx;
        left: 43rpx;
        padding-left: 10rpx;
        padding-top: 10rpx
    }
    .new_box{
        width: 100%;
        padding-left: 20rpx;
    }
    .group_img{
        width: 40rpx !important;
        height: 30rpx !important;
        margin-left: 10rpx;
        transform: translate(0,20%) !important;
    }
</style>
